package user_v1

import (
	"context"
	"gf-xb-api/cwt/mymiddleware"
	"gf-xb-api/internal/consts"
	"gf-xb-api/utility/xredis"

	"github.com/gogf/gf/v2/frame/g"
)

func (s *sUser) Logout(ctx context.Context) (output bool, err error) {

	r := g.RequestFromCtx(ctx)

	// 删除Redis key
	uuid := r.GetCtxVar(consts.JWT_INFO_UUID).String()
	deviceType := r.GetCtxVar(consts.JWT_INFO_DEVICETYPE).Int()

	redisKey := xredis.JwtTokenKey(uuid, deviceType)
	_, err = g.Redis().Del(ctx, redisKey)
	if err != nil {
		return false, err
	}

	// jwt logout
	mymiddleware.Auth().LogoutHandler(ctx)

	return true, nil
}
